﻿using BS.Infra;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BS.Write.Api.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        /// <summary>
        /// 中介者的引用
        /// </summary>
        private readonly IMediator _mediator;

        private readonly ILogger<UserController> _logger;

        public UserController(IMediator mediator, ILogger<UserController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> Login(LoginUserRequestDTO parm)
        {
            try
            {
                return await _mediator.Send(parm);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "登录失败");
                throw;
            }
        }
    }
}
